﻿using System;

using Rarous.TexyNet.Parser.Elements;
using Rarous.TexyNet.Parser.Formatter;

using Xunit;

namespace Rarous.TexyNet.Parser.Test {
  public class TexySpec {
    private readonly IronTexy _texy;

    public TexySpec() {
      _texy = new IronTexy();
    }

    [Fact]
    public void Texy_ShouldProcess_EmptyInput() {
      Assert.Equal(XhtmlFormatter.TexyNetSign, _texy.Process(String.Empty));
    }

    [Fact]
    public void Texy_ShouldProcess_SomeText() {
      Assert.NotEqual(XhtmlFormatter.TexyNetSign, _texy.Process("Texy je sexy!"));
    }

    [Fact]
    public void TexySharp_ShouldProcess_CustomFormatterAndCustomParser() {
      _texy.Formatter = new DummyFormatter();
      _texy.Parser = new DummyParser();
      Assert.Equal("dummy output", _texy.Process(null));
    }
  }

  internal class DummyParser : ITexyParser {
    private readonly Element _root = new Element();

    public Element Root {
      get {
        return _root;
      }
    }

    public void Parse(string input) {
    }
  }

  internal class DummyFormatter : ITexyFormatter<string> {
    private ITexySettings _configuration;
    private Element _root;

    public string Format() {
      return "dummy output";
    }

    public ITexySettings Configuration {
      get {
        return _configuration;
      }
      set {
        _configuration = value;
      }
    }

    public Element Root {
      get {
        return _root;
      }
      set {
        _root = value;
      }
    }
  }
}